﻿using System.Linq;
using System.Text;
using System.Diagnostics;
using System.Runtime.Serialization;
using System.Collections;
using System.Data;
using System.ComponentModel;
using System.Data.OracleClient;
namespace INTEX.DataBase.Tools
{
    public partial class INTEXDBC
    {
        public DataSet QueryAPARTK(DataRow dwData, int option = 1)
        {
            DataSet setReturn = new DataSet();
            DataSet Result = new DataSet();
            DataTable tbLocal = null;
            OracleCommand or1;
            // APZMANDANT  APZART APZVAR APZANRKRS APZALFDNR APZSTUFE

            or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 0:
                    or1.CommandText = "SELECT * FROM APARTK WHERE  ROWNUM<2 ";
                    break;
                case 1:
                    or1.CommandText = "SELECT * FROM APARTK WHERE  "
                        + "  APAKMANDANT=:APAKMANDANT  AND APAKANRKRS=:APAKANRKRS AND APAKALFDNR=:APAKALFDNR ";
                    or1.Parameters.Add("APAKMANDANT", OracleType.NVarChar).Value = dwData["APAKMANDANT"].ToString();
                    or1.Parameters.Add("APAKANRKRS", OracleType.NVarChar).Value = dwData["APAKANRKRS"].ToString();
                    or1.Parameters.Add("APAKALFDNR", OracleType.NVarChar).Value = dwData["APAKALFDNR"].ToString();
                    break;
                case 2:
                    or1.CommandText = "SELECT P.*,M.AMNRKRS,AMLFDNR,AMPOS FROM APARTK P JOIN AMSTAMM M ON   APAKPKSTKRS=AMKSTKRS AND APAKPKST=AMKST AND APAKMTYP=AMTYP AND AMSTDVAR='J'"
                    +" WHERE  APAKMANDANT=:APAKMANDANT  AND APAKANRKRS=:APAKANRKRS AND APAKALFDNR=:APAKALFDNR AND APAKAFOLGE=:APAKAFOLGE ";
                    or1.Parameters.Add("APAKMANDANT", OracleType.NVarChar).Value = dwData["APAKMANDANT"].ToString();
                    or1.Parameters.Add("APAKANRKRS", OracleType.NVarChar).Value = dwData["APAKANRKRS"].ToString();
                    or1.Parameters.Add("APAKALFDNR", OracleType.NVarChar).Value = dwData["APAKALFDNR"].ToString();
                    or1.Parameters.Add("APAKAFOLGE", OracleType.NVarChar).Value = dwData["APAKAFOLGE"].ToString();
                    break;
                case 9999:
                    or1.CommandText = "SELECT * FROM APARTK WHERE  ROWNUM<2 ";
                    break;
                default:
                    break;
            }
            Result = Connect2Proxy(or1);
            if (Result.Tables.Count > 0)
            {
                tbLocal = Result.Tables[0];
                tbLocal.TableName = "APARTK";
            }
            setReturn.Merge(Result);
            return setReturn;
        }

    }
}
